Skip to content

fix(audit): declare the partial flag on discord.role_changed - #216

Merged
guarzo merged 1 commit into
mainfrom
worktree-audit-role-changed-partial
Aug 10, 2026
Merged

fix(audit): declare the partial flag on discord.role_changed#216
guarzo merged 1 commit into
mainfrom
worktree-audit-role-changed-partial

Conversation

@guarzo

@guarzo guarzo commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Found while auditing the Details column for #215, fixed separately because it is
a different action and a different mechanism.

The bug

discord.role_changed has two writers, and both stamp a partial key on every
row:

  • src/jobs/discord-roles.ts:143 — the deprovision path, writing
    { removed, cause, partial }
  • src/jobs/discord-roles.ts:369 — the main sweep, writing
    { added, removed, tier, partial }

The PARTS entry declared added, removed, tier, and cause — not
partial. summarizeDetails counts undeclared keys toward the hidden-key
total, so every role-change row rendered a +1 more with nothing behind it.

Two costs. The +1 more was pure noise on rows where nothing was hidden, which
trains an admin to ignore the marker. And a row that was genuinely partial —
some roles failed to apply — announced that fact only as the same opaque count
it showed on every complete row, so the one case worth noticing was
indistinguishable from the noise.

The fix

One flag("partial", "partial") added to the declaration.

flag rather than scalar: it renders the word only when the value is truthy
while declaring the key either way, so complete rows say nothing instead of
carrying a partial false that would be noise on the overwhelming majority.
Placed last because it qualifies the whole change rather than naming a part of
it, and declared parts are never truncated (summarize.ts:405-407), so trailing
costs it no visibility.

Verification

Written test-first — the three new cases fail against the unfixed code:

AssertionError: expected '+alumni' to be '+alumni, partial'
AssertionError: expected '+alumni, +1 more' to be '+alumni'
AssertionError: expected '+alumni, +2 more' to be '+alumni, +1 more'

That last one is the bug stated precisely: partial inflating the hidden count
past the one key that was genuinely undeclared. All three pass after the change.

npm run typecheck, npm run lint, npm run format:check clean.
npm test → 92 files, 1490 tests passing. npm run build succeeds.

Scope

This fixes the one action. I did not systematically audit the other ~50
logAudit payload sites for the same declared-vs-written drift — that is a
broader sweep worth doing on its own, and the same class of bug would be
invisible in exactly the same way anywhere else it exists.

Touches summarize.ts alongside #215, but in a different region of PARTS
(the discord.* entries rather than the character-id ones). Either order
merges.

Summary by CodeRabbit

  • Bug Fixes

    • Audit summaries now display the partial indicator only when applicable.
    • Prevented the partial field from being incorrectly counted as an undisclosed change when false.
  • Tests

    • Added coverage for true, false, and undeclared audit fields.

Both writers stamp `partial` on every row they write (jobs/discord-roles.ts:143
on the deprovision path, :369 on the main sweep), but the PARTS entry declared
only added/removed/tier/cause. Undeclared keys count toward the hidden-key
total, so EVERY role-change row rendered a `+1 more` with nothing behind it --
and a row that was genuinely partial said so only as that same opaque count.

Declared with `flag` rather than `scalar`: the interesting state is the true
one, and "partial false" on the overwhelming majority of rows would be noise.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d3534b19-4d3e-46a3-a422-6e4d8d92e258

📥 Commits

Reviewing files that changed from the base of the PR and between f978dbd and 3282f93.

📒 Files selected for processing (2)
  • src/app/admin/audit/summarize.ts
  • tests/audit-summarize.test.ts

📝 Walkthrough

Walkthrough

The discord.role_changed audit summary now treats partial as a declared conditional field. Tests verify output for true, false, and undeclared fields.

Changes

Role change audit summaries

Layer / File(s) Summary
Handle conditional partial fields
src/app/admin/audit/summarize.ts, tests/audit-summarize.test.ts
At src/app/admin/audit/summarize.ts:327-339, partial renders only when true. Tests at tests/audit-summarize.test.ts:227-259 verify false values remain silent and undeclared fields count as hidden.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • guarzo/authGD#102: Introduced the related discord.role_changed summarization logic and tests.
  • guarzo/authGD#163: Modified Discord role auditing in the same code domain.

Poem

A partial flag joins the role-change tale,
True is shown; false stays pale.
Hidden fields now count with care,
Clear audit summaries fill the air.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title uses valid Conventional Commit syntax and describes the fix, but its summary names the implementation mechanism instead of the user-visible rendering effect. Change the summary to describe the user-visible effect, such as removing the misleading +1 more marker from role-change audit details.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the bug, fix, tests, verification, and scope, although it does not use all template headings and repeats CI checks.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@guarzo
guarzo merged commit 099f59e into main Aug 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant